<script type="text/javascript">
    /*<![CDATA[*/
    jQuery(function($) {
        //alert("hello");
        jQuery('a[rel="tooltip"]').tooltip();
        jQuery('a[rel="popover"]').popover();
    });
     function clickedAcceptBtn(obj)
    {
        //alert(obj.id);
        $("#"+obj.id).addClass('disabled btn-warning').text('Accepted already');
    }
     function clickedRejectBtn(obj)
    {
        //alert(obj.id);
        $("#"+obj.id).addClass('disabled btn-warning').text('Rejected already');
    }
</script>
<?php
$screen = Blyn::app()->getCurrentNode()->getUIManager()->getCurrentScreen();
$reqs = $screen->getJoinServiceRequests();

if ($screen->isAjaxLinkClicked('acceptBtn')) {
    if (isset($_POST['requestId']))
        $screen->addServiceMember($_POST['requestId'],'accept');
}

if ($screen->isAjaxLinkClicked('rejectBtn')) {
    if (isset($_POST['requestId']))
        $screen->addServiceMember($_POST['requestId'],'reject');
}
?>
<H4>Join Service Requests:</h4>
<table class="table table-hover">
    <tbody>
        <?php
        foreach ($reqs as $reqId => $request) {
            $sender_user = new BUser($request->sender['userId']);
            $sender_service = new BService($request->sender['serviceId']);
            $sender_sApp = BServiceApp::getInstanceById($request->sender['serviceAppId']);
            $ajaxAcceptBtn = $screen->buildAjaxLink('acceptBtn', 'Accept',NULL, 'processJoinServiceRequest',
                    array('type' => 'post', 'data' => array('requestId' => $reqId)), array('class' => 'btn btn-small btn-primary','onclick'=>'clickedAcceptBtn(this)'));
            $ajaxRejectBtn = $screen->buildAjaxLink('rejectBtn', 'Reject',NULL, 'processJoinServiceRequest', array('type' => 'post', 'data' => array('requestId' => $reqId)), array('class' => 'btn btn-small','onclick'=>'clickedRejectBtn(this)'));
            ?>
            <tr><td><p>From: <?php echo $sender_user->getLoginId(); ?>||<?php echo $sender_service->getName(); ?></p>                    
                    <p>ApplyingRole: <?php echo $request->data['applyingRole']; ?> </p>
                    <p>Message: <?php echo $request->data['senderMessage']; ?> </p>
                    <p>
                        <?php echo $ajaxAcceptBtn; ?>
                        <?php echo $ajaxRejectBtn; ?>
                    </p>
                </td></tr>
        <?php } ?>
    </tbody>
</table>

